package com.css.fxfzfxqh.modules.seismicHazardData.controller;

import cn.hutool.core.util.IdUtil;
import com.css.fxfzfxqh.base.response.RestResponse;
import com.css.fxfzfxqh.modules.seismicHazardData.entity.ArModelEntity;
import com.css.fxfzfxqh.modules.seismicHazardData.entity.SettingSeismicProcessEntity;
import com.css.fxfzfxqh.modules.seismicHazardData.param.arModel.ArModelPageParam;
import com.css.fxfzfxqh.modules.seismicHazardData.param.arModel.CountParam;
import com.css.fxfzfxqh.modules.seismicHazardData.service.SeismicImpactFieldService;
import com.css.fxfzfxqh.util.PlatformDateUtils;
import com.css.fxfzfxqh.util.PlatformObjectUtils;
import com.css.fxfzfxqh.web.PlatformSessionContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.persistence.Id;
import javax.servlet.http.HttpServletRequest;

/**
 * 地震影响场
 */
@RestController
@RequestMapping("seismicImpactField")
@Slf4j
public class SeismicImpactFieldController {

    @Autowired
    private SeismicImpactFieldService seismicImpactFieldService;

    /**
     * 新增
     *
     * @param arModelEntity
     * @return
     */
    @RequestMapping("saveArModel")
    public RestResponse saveArModel(@RequestBody ArModelEntity arModelEntity) {
        try {
            return seismicImpactFieldService.saveArModel(arModelEntity);
        } catch (Exception e) {
            log.error("新增模型失败:{}", e.getMessage(), e);
            return RestResponse.fail("新增模型失败!");
        }
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @GetMapping("deleteById")
    public RestResponse deleteById(String id) {
        try {
            return seismicImpactFieldService.deleteById(id);
        } catch (Exception e) {
            log.error("删除模型失败:{}", e.getMessage(), e);
            return RestResponse.fail("删除模型失败!");
        }
    }

    /**
     * 分页
     *
     * @param param
     * @return
     */
    @GetMapping("page")
    public RestResponse page(ArModelPageParam param, HttpServletRequest request) {
        try {
            return seismicImpactFieldService.page(param, request);
        } catch (Exception e) {
            log.error("分页查询模型失败:{}", e.getMessage(), e);
            return RestResponse.fail("查询模型失败!");
        }
    }

    /**
     * 根据id查
     *
     * @param id
     * @return
     */
    @GetMapping("getById")
    public RestResponse getById(String id) {
        try {
            return seismicImpactFieldService.getById(id);
        } catch (Exception e) {
            log.error("查询模型失败:{},id:{}", e.getMessage(), id, e);
            return RestResponse.fail("查询模型失败!");
        }
    }

    /**
     * 修改
     *
     * @param entity
     * @return
     */
    @PostMapping("updateById")
    public RestResponse updateById(@RequestBody ArModelEntity entity) {
        try {
            return seismicImpactFieldService.updateById(entity);
        } catch (Exception e) {
            log.error("修改模型失败:{},id:{}", e.getMessage(), entity.getId(), e);
            return RestResponse.fail("修改模型失败!");
        }
    }

    /**
     * 选择模型计算
     *
     * @param param
     * @return
     */
    @PostMapping("countInfluenceField")
    public RestResponse countInfluenceField(@RequestBody CountParam param) {
        try {
            return seismicImpactFieldService.countInfluenceField(param);
        } catch (Exception e) {
            log.error("根据模型生成地震影响场失败:{}", e.getMessage(), e);
            return RestResponse.fail("生成地震影响场失败!");
        }
    }

    /**
     * 手动填写计算
     */
    @PostMapping("countSettingSeismicProcess")
    public RestResponse countSettingSeismicProcess(@RequestBody SettingSeismicProcessEntity entity){
        try {
            return seismicImpactFieldService.countSettingSeismicProcess(entity);
        } catch (Exception e) {
            log.error("手动填写生成地震影响场失败:{}", e.getMessage(), e);
            return RestResponse.fail("生成地震影响场失败!");
        }
    }

    /**
     * 导入地震影响场
     */
    @GetMapping("importShp")
    public RestResponse importShp(String attachIds){
        try {
            return seismicImpactFieldService.importShp(attachIds);
        } catch (Exception e) {
            log.error("导入地震影响场失败:{}", e.getMessage(), e);
            return RestResponse.fail("导入地震影响场失败!");
        }
    }

    /**
     * 全部地震影响场
     * @return
     */
    @GetMapping("getAll")
    public RestResponse getAll(HttpServletRequest request){
        try {
            return seismicImpactFieldService.getAll(request);
        } catch (Exception e) {
            log.error("地震影响场列表展示失败:{}", e.getMessage(), e);
            return RestResponse.fail("查看失败!");
        }
    }

    /**
     * 根据id查询地震影响场
     * @param versionCode
     * @return
     */
    @GetMapping("getInfluencefliedById")
    public RestResponse getInfluencefliedById(String versionCode){
        try {
            return seismicImpactFieldService.getInfluencefliedById(versionCode);
        } catch (Exception e) {
            log.error("查询影响场失败:{}", e.getMessage(), e);
            return RestResponse.fail("查看失败!");
        }
    }

    /**
     * 根据id删除
     */
    @GetMapping("deleteInfluencefliedById")
    public RestResponse deleteInfluencefliedById(String versionCode){
        try {
            seismicImpactFieldService.deleteInfluencefliedById(versionCode);
            return RestResponse.succeed("删除成功");
        } catch (Exception e) {
            log.error("删除影响场失败:{}", e.getMessage(), e);
            return RestResponse.fail("删除失败!");
        }
    }
}
